Classe System.Collections.Generic.List<T>

Questo articolo fornisce osservazioni supplementari alla documentazione di riferimento per questa API.

La List<T> classe è l'equivalente generico della ArrayList classe . Implementa l'interfaccia IList<T> generica usando una matrice le cui dimensioni sono aumentate dinamicamente in base alle esigenze.

È possibile aggiungere elementi a un List<T> utilizzando i Add metodi o AddRange .

La List<T> classe usa sia un operatore di confronto di uguaglianza che un operatore di confronto degli ordini.

  • Metodi come Contains, IndexOfLastIndexOf, e Remove usano un operatore di confronto di uguaglianza per gli elementi dell'elenco. L'operatore di confronto di uguaglianza predefinito per il tipo T viene determinato nel modo seguente. Se il tipo T implementa l'interfaccia IEquatable<T> generica, l'operatore di confronto di uguaglianza è il Equals(T) metodo di tale interfaccia; in caso contrario, l'operatore di confronto di uguaglianza predefinito è Object.Equals(Object).

  • Metodi come BinarySearch e Sort usano un operatore di confronto degli ordini per gli elementi dell'elenco. L'operatore di confronto predefinito per il tipo T viene determinato come segue. Se il tipo T implementa l'interfaccia IComparable<T> generica, l'operatore di confronto predefinito è il CompareTo(T) metodo di tale interfaccia. In caso contrario, se il tipo T implementa l'interfaccia non generica IComparable , l'operatore di confronto predefinito è il CompareTo(Object) metodo di tale interfaccia. Se il tipo T implementa nessuna interfaccia, non è presente alcun operatore di confronto predefinito e deve essere fornito in modo esplicito un delegato di confronto o di confronto.

Non è garantito l'ordinamento List<T> di . È necessario ordinare prima List<T> di eseguire operazioni , ad esempio BinarySearch, che richiedono l'ordinamento di List<T> .

È possibile accedere a elementi di questa raccolta usando un indice integer. Gli indici in questa raccolta sono in base zero.

Solo .NET Framework: per oggetti di dimensioni molto grandi List<T> , è possibile aumentare la capacità massima a 2 miliardi di elementi in un sistema a 64 bit impostando l'attributo enabled dell'elemento <gcAllowVeryLargeObjects> di configurazione su true nell'ambiente di runtime.

List<T> accetta null come valore valido per i tipi di riferimento e consente elementi duplicati.

Per una versione non modificabile della List<T> classe , vedere ImmutableList<T>.

Considerazioni sulle prestazioni

Per decidere se usare la List<T> classe o ArrayList , entrambe con funzionalità simili, tenere presente che la List<T> classe offre prestazioni migliori nella maggior parte dei casi ed è indipendente dai tipi. Se per il tipo T della List<T> classe viene usato un tipo riferimento, il comportamento delle due classi è identico. Tuttavia, se viene usato un tipo valore per il tipo T, è necessario prendere in considerazione problemi di implementazione e boxing.

Se per il tipo Tviene usato un tipo valore , il compilatore genera un'implementazione della List<T> classe specifica per tale tipo di valore. Ciò significa che un elemento elenco di un List<T> oggetto non deve essere sottoposto a boxing prima che l'elemento possa essere utilizzato e dopo la creazione di circa 500 elementi elenco, la memoria salvata da elementi di elenco non boxing è maggiore della memoria utilizzata per generare l'implementazione della classe.

Assicurarsi che il tipo di valore usato per il tipo T implementi l'interfaccia IEquatable<T> generica. In caso contrario, i metodi come Contains devono chiamare il Object.Equals(Object) metodo , che riquadri l'elemento dell'elenco interessato. Se il tipo valore implementa l'interfaccia IComparable e si è proprietari del codice sorgente, implementare anche l'interfaccia IComparable<T> generica per impedire ai BinarySearch metodi e Sort di eseguire il boxing degli elementi elenco. Se non si è proprietari del codice sorgente, passare un IComparer<T> oggetto ai BinarySearch metodi e Sort .

È possibile usare l'implementazione specifica del List<T> tipo della classe anziché usare la ArrayList classe o scrivere manualmente una raccolta wrapper fortemente tipizzata. Ciò è dovuto al fatto che l'implementazione deve eseguire le operazioni già eseguite da .NET e il runtime .NET può condividere il codice e i metadati comuni del linguaggio intermedio, che l'implementazione non può eseguire.

Considerazioni su F#

La List<T> classe viene usata raramente nel codice F#. Gli elenchi, che sono invece non modificabili, sono in genere preferiti. Un F# List fornisce una serie ordinata e non modificabile di valori ed è supportata per l'uso nello sviluppo in stile funzionale. Se usato da F#, la List<T> classe viene in genere definita dall'abbreviazione del ResizeArray<'T> tipo per evitare conflitti di denominazione con gli elenchi F#.

Esempi

Nell'esempio seguente viene illustrato come aggiungere, rimuovere e inserire un semplice oggetto business in un oggetto List<T>.

using System;
using System.Collections.Generic;

// Simple business object. A PartId is used to identify the type of part
// but the part name can change.
public class Part : IEquatable<Part>
{
    public string PartName { get; set; }

    public int PartId { get; set; }

    public override string ToString()
    {
        return "ID: " + PartId + "   Name: " + PartName;
    }
    public override bool Equals(object obj)
    {
        if (obj == null) return false;
        Part objAsPart = obj as Part;
        if (objAsPart == null) return false;
        else return Equals(objAsPart);
    }
    public override int GetHashCode()
    {
        return PartId;
    }
    public bool Equals(Part other)
    {
        if (other == null) return false;
        return (this.PartId.Equals(other.PartId));
    }
    // Should also override == and != operators.
}

public class Example
{
    public static void Main()
    {
        // Create a list of parts.
        List<Part> parts =
        [
            // Add parts to the list.
            new Part() { PartName = "crank arm", PartId = 1234 },
            new Part() { PartName = "chain ring", PartId = 1334 },
            new Part() { PartName = "regular seat", PartId = 1434 },
            new Part() { PartName = "banana seat", PartId = 1444 },
            new Part() { PartName = "cassette", PartId = 1534 },
            new Part() { PartName = "shift lever", PartId = 1634 },
        ];

        // Write out the parts in the list. This will call the overridden ToString method
        // in the Part class.
        Console.WriteLine();
        foreach (Part aPart in parts)
        {
            Console.WriteLine(aPart);
        }

        // Check the list for part #1734. This calls the IEquatable.Equals method
        // of the Part class, which checks the PartId for equality.
        Console.WriteLine("\nContains(\"1734\"): {0}",
        parts.Contains(new Part { PartId = 1734, PartName = "" }));

        // Insert a new item at position 2.
        Console.WriteLine("\nInsert(2, \"1834\")");
        parts.Insert(2, new Part() { PartName = "brake lever", PartId = 1834 });

        //Console.WriteLine();
        foreach (Part aPart in parts)
        {
            Console.WriteLine(aPart);
        }

        Console.WriteLine("\nParts[3]: {0}", parts[3]);

        Console.WriteLine("\nRemove(\"1534\")");

        // This will remove part 1534 even though the PartName is different,
        // because the Equals method only checks PartId for equality.
        parts.Remove(new Part() { PartId = 1534, PartName = "cogs" });

        Console.WriteLine();
        foreach (Part aPart in parts)
        {
            Console.WriteLine(aPart);
        }
        Console.WriteLine("\nRemoveAt(3)");
        // This will remove the part at index 3.
        parts.RemoveAt(3);

        Console.WriteLine();
        foreach (Part aPart in parts)
        {
            Console.WriteLine(aPart);
        }

        /*

         ID: 1234   Name: crank arm
         ID: 1334   Name: chain ring
         ID: 1434   Name: regular seat
         ID: 1444   Name: banana seat
         ID: 1534   Name: cassette
         ID: 1634   Name: shift lever

         Contains("1734"): False

         Insert(2, "1834")
         ID: 1234   Name: crank arm
         ID: 1334   Name: chain ring
         ID: 1834   Name: brake lever
         ID: 1434   Name: regular seat
         ID: 1444   Name: banana seat
         ID: 1534   Name: cassette
         ID: 1634   Name: shift lever

         Parts[3]: ID: 1434   Name: regular seat

         Remove("1534")

         ID: 1234   Name: crank arm
         ID: 1334   Name: chain ring
         ID: 1834   Name: brake lever
         ID: 1434   Name: regular seat
         ID: 1444   Name: banana seat
         ID: 1634   Name: shift lever

         RemoveAt(3)

         ID: 1234   Name: crank arm
         ID: 1334   Name: chain ring
         ID: 1834   Name: brake lever
         ID: 1444   Name: banana seat
         ID: 1634   Name: shift lever


     */
    }
}

' Simple business object. A PartId is used to identify the type of part 
' but the part name can change. 
Public Class Part
    Implements IEquatable(Of Part)
    Public Property PartName() As String
        Get
            Return m_PartName
        End Get
        Set(value As String)
            m_PartName = value
        End Set
    End Property
    Private m_PartName As String

    Public Property PartId() As Integer
        Get
            Return m_PartId
        End Get
        Set(value As Integer)
            m_PartId = value
        End Set
    End Property
    Private m_PartId As Integer

    Public Overrides Function ToString() As String
        Return "ID: " & PartId & "   Name: " & PartName
    End Function
    Public Overrides Function Equals(obj As Object) As Boolean
        If obj Is Nothing Then
            Return False
        End If
        Dim objAsPart As Part = TryCast(obj, Part)
        If objAsPart Is Nothing Then
            Return False
        Else
            Return Equals(objAsPart)
        End If
    End Function
    Public Overrides Function GetHashCode() As Integer
        Return PartId
    End Function
    Public Overloads Function Equals(other As Part) As Boolean _
        Implements IEquatable(Of Part).Equals
        If other Is Nothing Then
            Return False
        End If
        Return (Me.PartId.Equals(other.PartId))
    End Function
    ' Should also override == and != operators.

End Class
Public Class Example
    Public Shared Sub Main()
        ' Create a list of parts.
        Dim parts As New List(Of Part)()

        ' Add parts to the list.
        parts.Add(New Part() With {
             .PartName = "crank arm",
             .PartId = 1234
        })
        parts.Add(New Part() With {
             .PartName = "chain ring",
             .PartId = 1334
        })
        parts.Add(New Part() With {
             .PartName = "regular seat",
             .PartId = 1434
        })
        parts.Add(New Part() With {
             .PartName = "banana seat",
             .PartId = 1444
        })
        parts.Add(New Part() With {
             .PartName = "cassette",
             .PartId = 1534
        })
        parts.Add(New Part() With {
             .PartName = "shift lever",
             .PartId = 1634
        })



        ' Write out the parts in the list. This will call the overridden ToString method
        ' in the Part class.
        Console.WriteLine()
        For Each aPart As Part In parts
            Console.WriteLine(aPart)
        Next


        ' Check the list for part #1734. This calls the IEquatable.Equals method
        ' of the Part class, which checks the PartId for equality.
        Console.WriteLine(vbLf & "Contains(""1734""): {0}", parts.Contains(New Part() With {
             .PartId = 1734,
             .PartName = ""
        }))

        ' Insert a new item at position 2.
        Console.WriteLine(vbLf & "Insert(2, ""1834"")")
        parts.Insert(2, New Part() With {
             .PartName = "brake lever",
             .PartId = 1834
        })


        'Console.WriteLine();
        For Each aPart As Part In parts
            Console.WriteLine(aPart)
        Next

        Console.WriteLine(vbLf & "Parts[3]: {0}", parts(3))

        Console.WriteLine(vbLf & "Remove(""1534"")")

        ' This will remove part 1534 even though the PartName is different,
        ' because the Equals method only checks PartId for equality.
        parts.Remove(New Part() With {
             .PartId = 1534,
             .PartName = "cogs"
        })

        Console.WriteLine()
        For Each aPart As Part In parts
            Console.WriteLine(aPart)
        Next

        Console.WriteLine(vbLf & "RemoveAt(3)")
        ' This will remove part at index 3.
        parts.RemoveAt(3)

        Console.WriteLine()
        For Each aPart As Part In parts
            Console.WriteLine(aPart)
        Next
    End Sub
    '
    '        This example code produces the following output:
    '        ID: 1234   Name: crank arm
    '        ID: 1334   Name: chain ring
    '        ID: 1434   Name: regular seat
    '        ID: 1444   Name: banana seat
    '        ID: 1534   Name: cassette
    '        ID: 1634   Name: shift lever
    '
    '        Contains("1734"): False
    '
    '        Insert(2, "1834")
    '        ID: 1234   Name: crank arm
    '        ID: 1334   Name: chain ring
    '        ID: 1834   Name: brake lever
    '        ID: 1434   Name: regular seat
    '        ID: 1444   Name: banana seat
    '        ID: 1534   Name: cassette
    '        ID: 1634   Name: shift lever
    '
    '        Parts[3]: ID: 1434   Name: regular seat
    '
    '        Remove("1534")
    '
    '        ID: 1234   Name: crank arm
    '        ID: 1334   Name: chain ring
    '        ID: 1834   Name: brake lever
    '        ID: 1434   Name: regular seat
    '        ID: 1444   Name: banana seat
    '        ID: 1634   Name: shift lever
    '   '
    '        RemoveAt(3)
    '
    '        ID: 1234   Name: crank arm
    '        ID: 1334   Name: chain ring
    '        ID: 1834   Name: brake lever
    '        ID: 1444   Name: banana seat
    '        ID: 1634   Name: shift lever
    '        

End Class

// Simple business object. A PartId is used to identify the type of part  
// but the part name can change.  
[<CustomEquality; NoComparison>]
type Part = { PartId : int ; mutable PartName : string } with
    override this.GetHashCode() = hash this.PartId
    override this.Equals(other) =
        match other with
        | :? Part as p -> this.PartId = p.PartId
        | _ -> false
    override this.ToString() = sprintf "ID: %i   Name: %s" this.PartId this.PartName

[<EntryPoint>]
let main argv = 
    // We refer to System.Collections.Generic.List<'T> by its type 
    // abbreviation ResizeArray<'T> to avoid conflicts with the F# List module.    
    // Note: In F# code, F# linked lists are usually preferred over
    // ResizeArray<'T> when an extendable collection is required.
    let parts = ResizeArray<_>()
    parts.Add({PartName = "crank arm" ; PartId = 1234})
    parts.Add({PartName = "chain ring"; PartId = 1334 })
    parts.Add({PartName = "regular seat"; PartId = 1434 })
    parts.Add({PartName = "banana seat"; PartId = 1444 })
    parts.Add({PartName = "cassette"; PartId = 1534 })
    parts.Add({PartName = "shift lever"; PartId = 1634 })

    // Write out the parts in the ResizeArray.  This will call the overridden ToString method
    // in the Part type
    printfn ""
    parts |> Seq.iter (fun p -> printfn "%O" p)

    // Check the ResizeArray for part #1734. This calls the IEquatable.Equals method 
    // of the Part type, which checks the PartId for equality.    
    printfn "\nContains(\"1734\"): %b" (parts.Contains({PartId=1734; PartName=""}))
    
    // Insert a new item at position 2.
    printfn "\nInsert(2, \"1834\")"
    parts.Insert(2, { PartName = "brake lever"; PartId = 1834 })

    // Write out all parts
    parts |> Seq.iter (fun p -> printfn "%O" p)

    printfn "\nParts[3]: %O" parts.[3]

    printfn "\nRemove(\"1534\")"
    // This will remove part 1534 even though the PartName is different, 
    // because the Equals method only checks PartId for equality.
    // Since Remove returns true or false, we need to ignore the result
    parts.Remove({PartId=1534; PartName="cogs"}) |> ignore

    // Write out all parts
    printfn ""
    parts |> Seq.iter (fun p -> printfn "%O" p)

    printfn "\nRemoveAt(3)"
    // This will remove the part at index 3.
    parts.RemoveAt(3)

    // Write out all parts
    printfn ""
    parts |> Seq.iter (fun p -> printfn "%O" p)

    0 // return an integer exit code

Nell'esempio seguente vengono illustrate diverse proprietà e metodi della List<T> classe generica di tipo string. Per un esempio di List<T> tipi complessi, vedere il Contains metodo .

Il costruttore senza parametri viene usato per creare un elenco di stringhe con la capacità predefinita. La Capacity proprietà viene visualizzata e quindi il Add metodo viene utilizzato per aggiungere diversi elementi. Gli elementi sono elencati e la Capacity proprietà viene nuovamente visualizzata, insieme Count alla proprietà , per indicare che la capacità è stata aumentata in base alle esigenze.

Il Contains metodo viene utilizzato per verificare la presenza di un elemento nell'elenco, il Insert metodo viene utilizzato per inserire un nuovo elemento al centro dell'elenco e il contenuto dell'elenco viene nuovamente visualizzato.

La proprietà predefinita Item[] (l'indicizzatore in C#) viene usata per recuperare un elemento, il Remove metodo viene usato per rimuovere la prima istanza dell'elemento duplicato aggiunto in precedenza e il contenuto viene visualizzato di nuovo. Il Remove metodo rimuove sempre la prima istanza che rileva.

Il TrimExcess metodo viene usato per ridurre la capacità in base al conteggio e vengono visualizzate le Capacity proprietà e Count . Se la capacità inutilizzata fosse stata inferiore al 10% della capacità totale, l'elenco non sarebbe stato ridimensionato.

Infine, il Clear metodo viene usato per rimuovere tutti gli elementi dall'elenco e vengono visualizzate le Capacity proprietà e Count .

List<string> dinosaurs = new List<string>();

Console.WriteLine("\nCapacity: {0}", dinosaurs.Capacity);

dinosaurs.Add("Tyrannosaurus");
dinosaurs.Add("Amargasaurus");
dinosaurs.Add("Mamenchisaurus");
dinosaurs.Add("Deinonychus");
dinosaurs.Add("Compsognathus");
Console.WriteLine();
foreach (string dinosaur in dinosaurs)
{
    Console.WriteLine(dinosaur);
}

Console.WriteLine("\nCapacity: {0}", dinosaurs.Capacity);
Console.WriteLine("Count: {0}", dinosaurs.Count);

Console.WriteLine("\nContains(\"Deinonychus\"): {0}",
    dinosaurs.Contains("Deinonychus"));

Console.WriteLine("\nInsert(2, \"Compsognathus\")");
dinosaurs.Insert(2, "Compsognathus");

Console.WriteLine();
foreach (string dinosaur in dinosaurs)
{
    Console.WriteLine(dinosaur);
}

// Shows accessing the list using the Item property.
Console.WriteLine("\ndinosaurs[3]: {0}", dinosaurs[3]);

Console.WriteLine("\nRemove(\"Compsognathus\")");
dinosaurs.Remove("Compsognathus");

Console.WriteLine();
foreach (string dinosaur in dinosaurs)
{
    Console.WriteLine(dinosaur);
}

dinosaurs.TrimExcess();
Console.WriteLine("\nTrimExcess()");
Console.WriteLine("Capacity: {0}", dinosaurs.Capacity);
Console.WriteLine("Count: {0}", dinosaurs.Count);

dinosaurs.Clear();
Console.WriteLine("\nClear()");
Console.WriteLine("Capacity: {0}", dinosaurs.Capacity);
Console.WriteLine("Count: {0}", dinosaurs.Count);

/* This code example produces the following output:

Capacity: 0

Tyrannosaurus
Amargasaurus
Mamenchisaurus
Deinonychus
Compsognathus

Capacity: 8
Count: 5

Contains("Deinonychus"): True

Insert(2, "Compsognathus")

Tyrannosaurus
Amargasaurus
Compsognathus
Mamenchisaurus
Deinonychus
Compsognathus

dinosaurs[3]: Mamenchisaurus

Remove("Compsognathus")

Tyrannosaurus
Amargasaurus
Mamenchisaurus
Deinonychus
Compsognathus

TrimExcess()
Capacity: 5
Count: 5

Clear()
Capacity: 5
Count: 0
 */
Public Class Example2

    Public Shared Sub Main()
        Dim dinosaurs As New List(Of String)

        Console.WriteLine(vbLf & "Capacity: {0}", dinosaurs.Capacity)

        dinosaurs.Add("Tyrannosaurus")
        dinosaurs.Add("Amargasaurus")
        dinosaurs.Add("Mamenchisaurus")
        dinosaurs.Add("Deinonychus")
        dinosaurs.Add("Compsognathus")

        Console.WriteLine()
        For Each dinosaur As String In dinosaurs
            Console.WriteLine(dinosaur)
        Next

        Console.WriteLine(vbLf & "Capacity: {0}", dinosaurs.Capacity)
        Console.WriteLine("Count: {0}", dinosaurs.Count)

        Console.WriteLine(vbLf & "Contains(""Deinonychus""): {0}",
            dinosaurs.Contains("Deinonychus"))

        Console.WriteLine(vbLf & "Insert(2, ""Compsognathus"")")
        dinosaurs.Insert(2, "Compsognathus")

        Console.WriteLine()
        For Each dinosaur As String In dinosaurs
            Console.WriteLine(dinosaur)
        Next
        ' Shows how to access the list using the Item property.
        Console.WriteLine(vbLf & "dinosaurs(3): {0}", dinosaurs(3))
        Console.WriteLine(vbLf & "Remove(""Compsognathus"")")
        dinosaurs.Remove("Compsognathus")

        Console.WriteLine()
        For Each dinosaur As String In dinosaurs
            Console.WriteLine(dinosaur)
        Next

        dinosaurs.TrimExcess()
        Console.WriteLine(vbLf & "TrimExcess()")
        Console.WriteLine("Capacity: {0}", dinosaurs.Capacity)
        Console.WriteLine("Count: {0}", dinosaurs.Count)

        dinosaurs.Clear()
        Console.WriteLine(vbLf & "Clear()")
        Console.WriteLine("Capacity: {0}", dinosaurs.Capacity)
        Console.WriteLine("Count: {0}", dinosaurs.Count)
    End Sub
End Class

' This code example produces the following output:
'
'Capacity: 0
'
'Tyrannosaurus
'Amargasaurus
'Mamenchisaurus
'Deinonychus
'Compsognathus
'
'Capacity: 8
'Count: 5
'
'Contains("Deinonychus"): True
'
'Insert(2, "Compsognathus")
'
'Tyrannosaurus
'Amargasaurus
'Compsognathus
'Mamenchisaurus
'Deinonychus
'Compsognathus
'
'dinosaurs(3): Mamenchisaurus
'
'Remove("Compsognathus")
'
'Tyrannosaurus
'Amargasaurus
'Mamenchisaurus
'Deinonychus
'Compsognathus
'
'TrimExcess()
'Capacity: 5
'Count: 5
'
'Clear()
'Capacity: 5
'Count: 0

[<EntryPoint>]
let main argv = 
    // We refer to System.Collections.Generic.List<'T> by its type 
    // abbreviation ResizeArray<'T> to avoid conflict with the List module.    
    // Note: In F# code, F# linked lists are usually preferred over
    // ResizeArray<'T> when an extendable collection is required.
    let dinosaurs = ResizeArray<_>()
 
    // Write out the dinosaurs in the ResizeArray.
    let printDinosaurs() =
        printfn ""
        dinosaurs |> Seq.iter (fun p -> printfn "%O" p) 
 
    
    printfn "\nCapacity: %i" dinosaurs.Capacity
 
    dinosaurs.Add("Tyrannosaurus")
    dinosaurs.Add("Amargasaurus")
    dinosaurs.Add("Mamenchisaurus")
    dinosaurs.Add("Deinonychus")
    dinosaurs.Add("Compsognathus")
 
    printDinosaurs()
 
    printfn "\nCapacity: %i" dinosaurs.Capacity
    printfn "Count: %i" dinosaurs.Count
 
    printfn "\nContains(\"Deinonychus\"): %b" (dinosaurs.Contains("Deinonychus"))
 
    printfn "\nInsert(2, \"Compsognathus\")"
    dinosaurs.Insert(2, "Compsognathus")
 
    printDinosaurs()
 
    // Shows accessing the list using the Item property.
    printfn "\ndinosaurs[3]: %s" dinosaurs.[3]
 
    printfn "\nRemove(\"Compsognathus\")"
    dinosaurs.Remove("Compsognathus") |> ignore
 
    printDinosaurs()
 
    dinosaurs.TrimExcess()
    printfn "\nTrimExcess()"
    printfn "Capacity: %i" dinosaurs.Capacity
    printfn "Count: %i" dinosaurs.Count
 
    dinosaurs.Clear()
    printfn "\nClear()"
    printfn "Capacity: %i" dinosaurs.Capacity
    printfn "Count: %i" dinosaurs.Count
 
    0 // return an integer exit code
 
    (* This code example produces the following output:
 
Capacity: 0
 
Tyrannosaurus
Amargasaurus
Mamenchisaurus
Deinonychus
Compsognathus
 
Capacity: 8
Count: 5
 
Contains("Deinonychus"): true
 
Insert(2, "Compsognathus")
 
Tyrannosaurus
Amargasaurus
Compsognathus
Mamenchisaurus
Deinonychus
Compsognathus
 
dinosaurs[3]: Mamenchisaurus
 
Remove("Compsognathus")
 
Tyrannosaurus
Amargasaurus
Mamenchisaurus
Deinonychus
Compsognathus
 
TrimExcess()
Capacity: 5
Count: 5
 
Clear()
Capacity: 5
Count: 0
    *)